﻿#region Usings
using System.Collections.Generic;
using System.Linq;

using BK.BlusinessLogic.Exceptions;
using BK.Model;
using BK.Repositories.Abstract;
#endregion

namespace BK.BlusinessLogic
{
    public class ImportStatusesBl
    {
        #region Readonly & Static Fields
        private readonly IImportStatusesRepository _importStatusesRepository;
        #endregion

        #region C'tors
        public ImportStatusesBl(IImportStatusesRepository importStatusesRepository)
        {
            _importStatusesRepository = importStatusesRepository;
        }
        #endregion

        #region Instance Methods
        public ImportStatus Add(ImportStatuses importStatus)
        {
            if (GetBy(importStatus) == null)
            {
                string name = importStatus.ToString();
                ImportStatus result = new ImportStatus
                    {
                        Name = name,
                        DisplayName = name
                    };
                _importStatusesRepository.Save(result);
                return result;
            }
            
            throw new UniqueException();
        }

        public ImportStatus GetBy(ImportStatuses importStatus)
        {
            return _importStatusesRepository.GetBy(importStatus);
        }
        #endregion
    }
}